from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from core import views as core_views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', core_views.dashboard, name='dashboard'),  # 根路径默认指向仪表盘
    path('login/', core_views.custom_login, name='login'),
    path('logout/', core_views.custom_logout, name='logout'),
    path('dashboard/', core_views.dashboard, name='dashboard'),  # 仪表盘路由
    
    # 服务器相关URL
    path('servers/', core_views.server_list, name='server_list'),
    path('servers/add/', core_views.server_add, name='server_add'),
    path('servers/edit/<int:pk>/', core_views.server_edit, name='server_edit'),
    path('servers/delete/<int:pk>/', core_views.server_delete, name='server_delete'),
    path('servers/test-connection/<int:pk>/', core_views.test_server_connection, name='test_server_connection'),
    
    # 任务相关URL
    path('tasks/', core_views.task_list, name='task_list'),
    path('tasks/add/', core_views.task_add, name='task_add'),
    path('tasks/edit/<int:pk>/', core_views.task_edit, name='task_edit'),
    path('tasks/delete/<int:pk>/', core_views.task_delete, name='task_delete'),
    path('tasks/run/<int:pk>/', core_views.run_task, name='run_task'),
    path('tasks/log/<int:pk>/', core_views.task_log, name='task_log'),
    
    # 日志相关URL
    path('logs/', core_views.log_list, name='log_list'),
    path('logs/<int:pk>/', core_views.log_detail, name='log_detail'),
    
    # 报表相关URL
    path('reports/task-summary/', core_views.task_summary_report, name='task_summary_report'),
    path('reports/server-activity/', core_views.server_activity_report, name='server_activity_report'),

    # 数据库管理模块（与SimpleUI菜单URL保持一致）
    path('db-connections/', core_views.db_connection_list, name='db_connection_list'),
    path('db-connections/create/', core_views.db_connection_create, name='db_connection_create'),
    path('db-connections/<int:pk>/edit/', core_views.db_connection_edit, name='db_connection_edit'),
    path('db-connections/<int:pk>/delete/', core_views.db_connection_delete, name='db_connection_delete'),
    path('db-connections/<int:pk>/test/', core_views.db_test_connection, name='db_test_connection'),
    
    path('db-tools/query-test/', core_views.sql_query_test, name='sql_query_test'),
    path('db-tools/procedure-analysis/', core_views.stored_procedure_analysis, name='stored_procedure_analysis'),
]

# 开发环境下的媒体文件URL配置（生产环境需通过Web服务器配置静态文件）
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)